﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin1_Company : System.Web.UI.Page
{
    eStoreDataContext db = new eStoreDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        rpt_Category.DataSource = db.Companies;
        rpt_Category.DataBind();
    }
    protected void lbt_Edit_Click(object sender, EventArgs e)
    {
        panel_Edit.Visible = true;
        int companyid = int.Parse(((LinkButton)sender).CommandArgument.ToString());
        var compa = db.Companies.Single(c => c.CompanyId == companyid);
        txt_CompanyId_Edit.Text = companyid.ToString();
        txt_Name_Edit.Text = compa.Name;
        txt_Address_Edit.Text = compa.Address;
        txt_City_Edit.Text = compa.City;
        txt_National_Edit.Text = compa.National;
        txt_Email_Edit.Text = compa.Email;
        txt_Phone_Edit.Text = compa.Phone;
        txt_HotLine_Edit.Text = compa.HotLine;
    }
    protected void btnSaveEdit_Click(object sender, EventArgs e)
    {
        try
        {
            // tim 
            var compa = db.Companies.Single(c => c.CompanyId == int.Parse(txt_CompanyId_Edit.Text));
            compa.Name = txt_Name_Edit.Text;
            compa.Address = txt_Address_Edit.Text;
            compa.City = txt_City_Edit.Text;
            compa.National = txt_National_Edit.Text;
            compa.Email = txt_Email_Edit.Text;
            compa.Phone = txt_Phone_Edit.Text;
            compa.HotLine = txt_HotLine_Edit.Text;
            //3 Luu
            db.SubmitChanges();
            panel_Edit.Visible = false;
            Response.Redirect("Guide.aspx");
        }
        catch (Exception ex)
        {
                Response.Write("<script> alert('Chỉnh sửa không thành công');</script>");
                txt_Name_Edit.Focus();
        }
    }
    protected void lbt_ClosEdit_Click(object sender, EventArgs e)
    {
        panel_Edit.Visible = false;
    }
}